// The Vue build version to load with the `import` command
// The Vue build version to load with the `import` command
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'

import Less from 'Less'

import Router from 'vue-router'

//引用富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
 //引入富文本css
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
//富文本编辑器添加实例
Vue.use(VueQuillEditor)

import JsonExcel from "vue-json-excel";
Vue.component("downloadExcel", JsonExcel)


const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


import ElementUI from 'element-ui';


Vue.use(ElementUI);


import uploadImg from './components/uploadImg'
Vue.component("uploadImg", uploadImg)

import axios from 'axios'
import qs from 'qs'


import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)

//节流指令

axios.defaults.timeout = 5000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.baseURL = '';

axios.interceptors.request.use((config) => {
  if (config.method === 'post') {
    config.data = qs.stringify(config.data);
  }
  return config;
}, (error) => {
  return Promise.reject(error);
});
Vue.prototype.$axios = axios //全局注册，使用方法为:this.$axios 

Vue.config.productionTip = false

//全局配置接口
import $api from './util/requestUrl'
Vue.prototype.$api = $api

//接口
import $https from './util/https'
Vue.prototype.$https = $https.https

// 路由
import {getRoute} from "./router"; 
// let isLogin = sessionStorage.getItem("isLogin");
let isLogin = localStorage.getItem('isLogin');
console.log('登录权限是：',isLogin)

var routers = getRoute(0);
if (isLogin == -1) {
  routers = getRoute(-1);
}else if (isLogin>0){
  routers = getRoute(1)
} else {
  routers = getRoute(0);
}
// console.log(routers,'信息啊',isLogin)
router.options.routes = routers;
router.addRoutes(routers);

if(!isLogin){
  router.push('/Login')
}

router.beforeEach((to, from, next) => {
  if (to.path == "/") {
    next({ path: '/Login' })
  } else {
    next()
  }
  
})




/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
